package com.foreveross.bsl.monitor.web;

import java.io.IOException;
import java.util.Date;
import javax.inject.Inject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.foreveross.bsl.auth.Auth;
import com.foreveross.bsl.web.BaseController;
import com.sun.istack.logging.Logger;

@Controller
@RequestMapping("/monitor")
public class AuthController extends BaseController
{

	private Logger log = Logger.getLogger(AuthController.class);
	//@Inject
	private Message message;

	@RequestMapping(value = "index")
	public ModelAndView index(ModelAndView modelAndView,String url) throws IOException
	{
		log.info("come here means that user aready logined");
		Date date = new Date();
		String token = String.valueOf(date.getTime() ^ message.getPassword());
		Auth auth=this.getCurrentUser();
		String userName=auth.getUsername();
		if ("".equals(url) || url == null)
		{
			url = message.getMonitorUrl() + "?token=" + token+"&userName="+userName;
		}
		else
		{
			url = url + "?token=" + token+"&userName="+userName;
		}
		return new ModelAndView(new RedirectView(url));
	}

	@Override
	protected String getModuleMenuName()
	{
		log.info("return nothing");
		return null;
	}

}
